package edu.mse.camel.client.whiteboard.gef.ui.figures;

import java.util.List;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Polyline;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;

import edu.mse.camel.client.whiteboard.gef.ui.WhiteBoardUtil;
import edu.mse.camel.client.whiteboard.gef.whiteboard.FreeWritingShape;
import edu.mse.camel.client.whiteboard.gef.whiteboard.XY;

public class PointShapeFigure extends Figure {

	private List<XY> points;
	private FreeWritingShape shape;
	
	public void paintFigure(Graphics g) {
		for (int i=0 ; i<points.size() ; ++i) {
			
			
		}
		
		
		points = shape.getPoints();
		Point loc = shape.getLocation();
		PointList pList = new PointList();
		for (int i=0 ; i < points.size() ; ++i) {
			XY xy = points.get(i);
			Point p = new Point(xy.getX() + loc.x, xy.getY() + loc.y);
			pList.addPoint(p);
		}
		g.setLineWidth(WhiteBoardUtil.FIGURE_WIDTH);
		g.drawPolyline(pList);
		//g.
	}
	
	private void drawPointFigure() {
		Polyline line = new Polyline();
		line.setLineWidth(WhiteBoardUtil.FIGURE_WIDTH);
		points = shape.getPoints();
		Point loc = shape.getLocation();
		
		for (int i = 0; i < points.size(); i++) {
			XY xy = points.get(i);
			Point p = new Point(xy.getX() + loc.x, xy.getY() + loc.y);
			//Point p = new Point(xy.getX(), xy.getY());
			line.addPoint(p);
		}
		line.setForegroundColor(
				WhiteBoardUtil.createColorFromRGB(shape.getColor()));
		add(line);
	}

	public PointShapeFigure(FreeWritingShape shape) {
		super();
		this.shape = shape;
		drawPointFigure();
	}

}
